﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StyleCopViolationFactory.cs" company="StyleCop for ReSharper Development Team">
//   Copyright (c) StyleCop for ReSharper Development Team. All rights reserved.
// </copyright>
// <summary>
//   Defines the StyleCopViolationFactory type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace StyleCop.For.ReSharper.Violations
{
    #region Using Directives

    using JetBrains.DocumentModel;
    using JetBrains.ReSharper.Daemon;

    using Microsoft.StyleCop;
    using Microsoft.StyleCop.CSharp;

    using StyleCop.For.ReSharper.Options;

    #endregion

    /// <summary>
    /// Factory class for getting HighLights for StyleCop violations.
    /// </summary>
    public static class StyleCopViolationFactory
    {
        #region Public Methods

        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="violation">
        /// The <see cref="Microsoft.StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <param name="element">
        /// <see cref="CsElement"/>of the violation.
        /// </param>
        /// <param name="lineNumber">
        /// Line number where the violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ViolationEventArgs violation, DocumentRange documentRange, CsElement element, int lineNumber)
        {
            var ruleID = violation.Violation.Rule.CheckId;
            var highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            var severity = HighlightingSettingsManager.Instance.Settings.GetSeverity(highlightID);

            switch (severity)
            {
                case Severity.ERROR:
                    return new StyleCopViolationError(violation, documentRange, element, lineNumber);
                case Severity.HINT:
                    return new StyleCopViolationHint(violation, documentRange, element, lineNumber);
                case Severity.INFO:
                    return new StyleCopViolationError(violation, documentRange, element, lineNumber);
                case Severity.SUGGESTION:
                    return new StyleCopViolationSuggestion(violation, documentRange, element, lineNumber);
                case Severity.WARNING:
                    return new StyleCopViolationWarning(violation, documentRange, element, lineNumber);
                default:
                    return new StyleCopViolationDoNotShow(violation, documentRange, element, lineNumber);
            }
        }

        #endregion
    }
}